import FormDesigner from './form-designer/FormDesigner.vue'
import DragTool from './drag-tool/DragTool.vue'
import Struct from './struct/Struct.vue'
import Fetch from './fetch/Fetch.vue'
import Validate from './validate/Validate.vue'
import DragBox from './drag-box/DragBox.vue'
import Required from './required/Required.vue'
import TableOptions from './table-options/TableOptions.vue'
import { designerForm } from '../utils/form'
import FcEditor from '@form-create/component-wangeditor'
import draggable from 'vuedraggable/src/vuedraggable'
import unique from '@form-create/utils/lib/unique'
import { makeOptionsRule } from '../utils/index'
import formCreate from '../utils/form'
import globalUseLocale, { t } from '../utils/locale'

const addComponent = (id, component) => {
  designerForm.component(id, component)
  formCreate.component(id, component)
}

designerForm.component('draggable', draggable)
designerForm.component('DragTool', DragTool)
designerForm.component('DragBox', DragBox)
designerForm.component('Validate', Validate)
designerForm.component('Struct', Struct)
designerForm.component('Fetch', Fetch)
designerForm.component('Required', Required)
designerForm.component('TableOptions', TableOptions)
addComponent('FcEditor', FcEditor)

designerForm.register('_fc', {
  init(fc, rule) {
    rule._id = unique()
    // if (fc.repeat)
    //     rule.field = unique();
    if (fc.value) {
      rule.effect._fc = false
    }
  }
})

designerForm.register('_fc_tool', {
  init(_, rule) {
    rule.props.unique = unique()
  }
})

const install = function (Vue) {
  Vue.component('FormDesigner', FormDesigner)
}

FormDesigner.install = install
FormDesigner.makeOptionsRule = makeOptionsRule
FormDesigner.formCreate = formCreate
FormDesigner.designerForm = designerForm
FormDesigner.component = addComponent
FormDesigner.useLocale = globalUseLocale
FormDesigner.t = t

export default FormDesigner

export { formCreate, designerForm }
